<?php
session_start();
$connect=mysql_connect('localhost', 'root', '559478');
mysql_select_db('elearn');
mysql_query("SET NAMES utf8");

$user = $_SESSION['username'];
$to = $_POST['to'];
$nickname=trim(addslashes(htmlspecialchars($_POST['nickname'])));
$theme=trim(addslashes(htmlspecialchars($_POST['topic'])));
$message=trim(addslashes(htmlspecialchars($_POST['text'])));
$date_added=time();


$sql="INSERT INTO messages(`from`, `to`, `topic`, `text`, `date`, `nickname`)
										VALUES ('$user', '$to', '$theme', '$message', '$date_added', '$nickname')";
$result = mysql_query($sql) or die (mysql_error());

if($result) {
	echo "send";
} else {
	echo "sended";
}